/**
 * 波形线条容器
 * ibio-develop
 * 2008-11-22 17:42
 */
package com.ibio8.components.wave {
	import flash.display.Sprite;
	
	public class  WaveBody extends Sprite {
		public var sp1:Sprite;
		public var sp2:Sprite;
		
		protected var m_mask:Sprite;
		protected var m_w:Number;
		protected var m_h:Number;
		protected var m_lineWdth:Number = 2;
		protected var m_lineColor:uint = 0x2AEAEB;
		protected var m_lineAlpha:Number = 0.75;
		
		public function WaveBody() {
			m_mask = new Sprite();
			sp1 = new Sprite();
			sp2 = new Sprite();
			this.addChild(sp1);
			this.addChild(sp2);
			this.addChild(m_mask);
		}
		
		/**
		 * 设置画出的线的样式
		 * @param	lineWidth	宽度
		 * @param	lineColor	颜色
		 * @param	lineAlpha	透明度
		 */
		public function setLineStyle(lineWidth:Number, lineColor:Number, lineAlpha:Number):void {
			m_lineWdth = lineWidth;
			m_lineColor = lineColor;
			m_lineAlpha = lineAlpha;
		}
		
		public function setSize(w:Number, h:Number):void {
			m_w = w;
			m_h = h;
			setWaveMask();
		}
		
		//是否使线也模糊
		public function set isBlur(value:Boolean):void {
			if (value) {
				this.width = m_w;
				this.height = m_h;
			}
		}
		
		public function get w():Number {
			return m_w;
		}
		
		public function get h():Number {
			return m_h;
		}
		
		public function reset():void {
			sp2.x = sp1.x = m_w / 2;
			sp2.y = sp1.y = m_h / 2;
			clear();
			applyStyle();
		}
		
		public function clear():void {
			this.graphics.clear();
			sp1.graphics.clear();					
			sp2.graphics.clear();
		}
		
		public function applyStyle():void {
			this.graphics.lineStyle(m_lineWdth, m_lineColor, m_lineAlpha);		
			sp1.graphics.lineStyle(m_lineWdth, m_lineColor, m_lineAlpha);
			sp2.graphics.lineStyle(m_lineWdth, m_lineColor, m_lineAlpha);
		}
		
		protected function setWaveMask():void {
			clear();
			m_mask.graphics.beginFill(0xFFFFFF);
			m_mask.graphics.drawRect(0, 0, m_w, m_h);
			m_mask.graphics.endFill();
			this.mask = m_mask;
		}
	}
}